package com.demo.service.impl;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.springframework.stereotype.Service;
import com.demo.bean.Asset;
import com.demo.bean.DongHuan;
import com.demo.bean.Event;
import com.demo.service.JsonManageService;
import com.demo.util.JSONReadUtil;

import net.sf.json.JSON;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Service
public class JsonManageServiceImpl implements JsonManageService {
	Random sum = new Random();

	/**
	 * 随机产生架式设备，用于ITVOP
	 * 
	 * @param Assetlist
	 * @param Racklist
	 * @param DCID
	 * @param J
	 * @param G
	 * @return
	 */
	@Override
	public JSON JsonManage(List<Asset> Assetlist, List<String> Racklist, String DCID, int J, int G) {
		JSONArray jsonArray = new JSONArray();
		JSON json = new JSONArray();
		List<Map<String, Object>> jiashilist;

		String[] ipdizhi = { "192.168.22.13", "192.168.200.1", "192.168.200.3", "192.168.200.4", "192.168.200.5" };
		String[] suoshubumen = { "网络通信组", "运维技术组", "机房环境组=1", "机房环境组-2", "机房环境组-3" };
		String[] yewuyongtu = { "计划应用服务器2", "计划应用服务器3", "计划应用服务器4", "计划通讯服务器1", "辅助决策服务器1" };
		String[] fuzheren = { "王洋", "徐九玲", "王志民", "徐明", "李亮" };
		String[] suoshuquyu = { "数据中心一区", "数据中心二区", "数据中心三区", "数据中心四区", "数据中心五区" };
		String[] xuliehao = { "2T4BN2X", "3T48D2X", "3T48D5X", "78N029R", "78G06GP" };

		for (int l = 0; l < Racklist.size(); l++) {
			jiashilist = shujijiashi(Assetlist, J, G);
			for (int i = 0; i < jiashilist.size(); i++) {
				String xinhao = (String) jiashilist.get(i).get("xinhao");
				String Uwei = (String) jiashilist.get(i).get("Uwei");
				String suoshu = Racklist.get(l);
				int mn = sum1(4, 0);
				Map<String, Object> datamap = new HashMap<String, Object>();
				datamap.put("编号", suoshu + "00" + (1 + i));
				datamap.put("_DCID_", DCID);
				datamap.put("_PareCateName_", "机柜");
				datamap.put("U位", Uwei);
				datamap.put("所属", suoshu);
				datamap.put("设备型号", xinhao);
				datamap.put("布局", "前");
				// 增加属性
				datamap.put("IP地址", ipdizhi[mn]);
				datamap.put("所属部门", suoshubumen[mn]);
				datamap.put("业务用途", yewuyongtu[mn]);
				datamap.put("负责人", fuzheren[mn]);
				datamap.put("所属区域", suoshuquyu[mn]);
				datamap.put("出厂序列号", xuliehao[mn]);

				JSONObject datajsonObj = JSONObject.fromObject(datamap);
				// 由Map生成JSONObject
				Map<String, Object> cimap = new HashMap<String, Object>();

				cimap.put("data", datajsonObj);
				cimap.put("domain", "");
				cimap.put("oper", "ADD");
				cimap.put("categoryName", "架式设备");
				cimap.put("ciName", suoshu + "00" + (1 + i));

				JSONObject cijsonObj = JSONObject.fromObject(cimap);
				jsonArray.add(cijsonObj);

			}
		}
		// 在进行json嵌套
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("CI", jsonArray);
		JSONObject jsonObj = JSONObject.fromObject(map);
		json = jsonObj;
		return json;
	}

	/**
	 * 随机产生架式设备，用于Tarsier
	 * 
	 * @param Assetlist
	 * @param Racklist
	 * @param DCID
	 * @param J
	 * @param G
	 * @return
	 */
	public JSON JsonDataManage(List<Asset> Assetlist, List<String> Racklist, int J, int G) {
		JSONArray jsonArray = new JSONArray();
		JSON json = new JSONArray();
		List<Map<String, Object>> jiashilist;

		String[] ipdizhi = { "192.168.22.13", "192.168.200.1", "192.168.200.3", "192.168.200.4", "192.168.200.5" };
		String[] suoshubumen = { "网络通信组", "运维技术组", "机房环境组=1", "机房环境组-2", "机房环境组-3" };
		String[] yewuyongtu = { "计划应用服务器2", "计划应用服务器3", "计划应用服务器4", "计划通讯服务器1", "辅助决策服务器1" };
		String[] fuzheren = { "王洋", "徐九玲", "王志民", "徐明", "李亮" };
		String[] suoshuquyu = { "数据中心一区", "数据中心二区", "数据中心三区", "数据中心四区", "数据中心五区" };
		String[] xuliehao = { "2T4BN2X", "3T48D2X", "3T48D5X", "78N029R", "78G06GP" };

		for (int l = 0; l < Racklist.size(); l++) {
			jiashilist = shujijiashi(Assetlist, J, G);
			for (int i = 0; i < jiashilist.size(); i++) {
				String xinhao = (String) jiashilist.get(i).get("xinhao");
				String Uwei = (String) jiashilist.get(i).get("Uwei");
				String suoshu = Racklist.get(l);
				int mn = sum1(4, 0);
				Map<String, Object> datamap = new HashMap<String, Object>();
				datamap.put("编号", suoshu + "00" + (1 + i));
				datamap.put("设备名称", xinhao);
				datamap.put("U位", Uwei);
				datamap.put("所属", suoshu);
				datamap.put("设备型号", xinhao);
				datamap.put("布局", "前");
				// 增加属性
				datamap.put("IP地址", ipdizhi[mn]);
				datamap.put("所属部门", suoshubumen[mn]);
				datamap.put("业务用途", yewuyongtu[mn]);
				datamap.put("负责人", fuzheren[mn]);
				datamap.put("所属区域", suoshuquyu[mn]);
				datamap.put("出厂序列号", xuliehao[mn]);

				JSONObject datajsonObj = JSONObject.fromObject(datamap);
				// 由Map生成JSONObject
				JSONObject cijsonObj = JSONObject.fromObject(datajsonObj);
				jsonArray.add(cijsonObj);

			}
		}
		// 在进行json嵌套
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("data", jsonArray);
		JSONObject jsonObj = JSONObject.fromObject(map);
		json = jsonObj;
		return json;
	}

	/**
	 * 产生随机间隔数
	 * 
	 * @param J 间隔值
	 * @return
	 */
	public int suijiJ(int J) {
		int sum = (int) (1 + Math.random() * (J));
		return sum;
	}

	/**
	 * 产生随机架势设备U位信息的list-map
	 * 
	 * @param Assetlist
	 * @param J
	 * @param G
	 * @return
	 */
	public List<Map<String, Object>> shujijiashi(List<Asset> Assetlist, int J, int G) {
		List<Map<String, Object>> mplist = new ArrayList<Map<String, Object>>();
		int Ugao1 = 1;
		int Ugao2;
		for (int i = 0; i < G; i++) {
			int sujinum = sum.nextInt(Assetlist.size());
			String xinhao = Assetlist.get(sujinum).getDeviceType();
			int U = Integer.parseInt(Assetlist.get(sujinum).getuHigh());
			Ugao2 = (Ugao1 + U) - 1;
			String Uwei = Ugao1 + "-" + Ugao2;
			Map<String, Object> jiashimap = new HashMap<String, Object>();
			jiashimap.put("xinhao", xinhao);
			jiashimap.put("Uwei", Uwei);
			// System.out.println("设备型号清单:"+jiashimap);
			mplist.add(jiashimap);
			Ugao1 = (Ugao2 + 1) + suijiJ(J);
			if (Ugao1 >= (G - 4)) {
				break;
			}
		}
		return mplist;
	}

	/**
	 * 随机产生性能数据
	 * 
	 * @param donghuanmap
	 * @return
	 */
	public JSON donghuanManage(Map<String, List<String>> donghuanmap, String path) {
		// 读取设置阈值
		JSONReadUtil jsonReadUtil = new JSONReadUtil();
		@SuppressWarnings("static-access")
		String jsonstr = jsonReadUtil.readFile(path);
		JSONObject jsonsetp = JSONObject.fromObject(jsonstr);

		JSONArray jsonArray = new JSONArray();
		JSON json = new JSONArray();
		// 修改为时间戳
		/*
		 * Date date=new Date(); DateFormat format=new SimpleDateFormat(
		 * "yyyy-MM-dd HH:mm:ss"); String time=format.format(date);
		 */
		String time = String.valueOf(System.currentTimeMillis());
		List<String> wsdlist = donghuanmap.get("温湿度");
		List<String> pdglist = donghuanmap.get("配电柜");
		List<String> ktlist = donghuanmap.get("空调");
		List<String> upslist = donghuanmap.get("UPS");
		List<String> fdjlist = donghuanmap.get("发电机");

		if (null != wsdlist && wsdlist.size() != 0) {
			for (int i = 0; i < wsdlist.size(); i++) {
				JSONObject ajsonObj = perf(wsdlist.get(i), "温度",
						sum(jsonsetp.getInt("wdmax"), jsonsetp.getInt("wdmin")), "℃", "_", time);
				JSONObject bjsonObj = perf(wsdlist.get(i), "湿度",
						sum(jsonsetp.getInt("sdmax"), jsonsetp.getInt("sdmin")), "%", "_", time);
				jsonArray.add(ajsonObj);
				jsonArray.add(bjsonObj);
			}
		}
		if (null != pdglist && pdglist.size() != 0) {
			for (int i = 0; i < pdglist.size(); i++) {
				JSONObject ajsonObj = perf(pdglist.get(i), "总电压",
						sum(jsonsetp.getInt("zdymax"), jsonsetp.getInt("zdymax")), "V", "_", time);
				JSONObject bjsonObj = perf(pdglist.get(i), "总电流",
						sum(jsonsetp.getInt("zdlmax"), jsonsetp.getInt("zdlmin")), "A", "_", time);
				jsonArray.add(ajsonObj);
				jsonArray.add(bjsonObj);
			}
		}
		if (null != ktlist && ktlist.size() != 0) {
			for (int i = 0; i < ktlist.size(); i++) {
				JSONObject ajsonObj = perf(ktlist.get(i), "回风温度",
						sum(jsonsetp.getInt("hfwdmax"), jsonsetp.getInt("hfwdmin")), "℃", "_", time);
				JSONObject bjsonObj = perf(ktlist.get(i), "回风湿度",
						sum(jsonsetp.getInt("hfsdmax"), jsonsetp.getInt("hfsdmin")), "%", "_", time);
				jsonArray.add(ajsonObj);
				jsonArray.add(bjsonObj);
			}
		}
		if (null != upslist && upslist.size() != 0) {
			for (int i = 0; i < upslist.size(); i++) {
				JSONObject ajsonObj = perf(upslist.get(i), "输入电压",
						sum(jsonsetp.getInt("srdymax"), jsonsetp.getInt("srdymin")), "V", "_", time);
				JSONObject bjsonObj = perf(upslist.get(i), "输出电压",
						sum(jsonsetp.getInt("scdymax"), jsonsetp.getInt("scdymin")), "V", "_", time);
				jsonArray.add(ajsonObj);
				jsonArray.add(bjsonObj);
			}
		}
		if (null != fdjlist && fdjlist.size() != 0) {
			for (int i = 0; i < fdjlist.size(); i++) {
				JSONObject ajsonObj = perf(fdjlist.get(i), "电压",
						sum(jsonsetp.getInt("dymax"), jsonsetp.getInt("dymin")), "V", "_", time);
				JSONObject bjsonObj = perf(fdjlist.get(i), "电流",
						sum(jsonsetp.getInt("dlmax"), jsonsetp.getInt("dlmin")), "A", "_", time);
				jsonArray.add(ajsonObj);
				jsonArray.add(bjsonObj);
			}
		}
		json = jsonArray;
		// System.out.println(json);
		return json;
	}

	/**
	 * 性能组装成json
	 * 
	 * @param ci
	 * @param kpi
	 * @param value
	 * @param unit
	 * @param desc
	 * @param time
	 * @return
	 */
	public JSONObject perf(String ci, String kpi, String value, String unit, String desc, String time) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("ci", ci);
		map.put("kpi", kpi);
		map.put("instance", "_");
		map.put("value", value);
		map.put("unit", unit);
		map.put("time", time);
		map.put("desc", desc);
		JSONObject jsonObj = JSONObject.fromObject(map);
		return jsonObj;
	}

	/**
	 * 在一定范围内取随机数，返回值为String
	 * 
	 * @param max
	 * @param min
	 * @return
	 */
	public String sum(int max, int min) {
		int sum = (int) (min + Math.random() * (max - min + 1));
		String sumstring = Integer.toString(sum);
		return sumstring;
	}

	/**
	 * 在一定范围内取随机数，返回值为Int
	 * 
	 * @param max
	 * @param min
	 * @return
	 */
	public int sum1(int max, int min) {
		int sum1 = (int) (min + Math.random() * (max - min + 1));
		return sum1;
	}

	/**
	 * itvop-tarsier 随机产生告警数据
	 * 
	 * @param eventlist 告警的设备编号集合
	 * @return
	 */
	public List<JSON> eventManage(List<String> eventlist, String path) {
		// TODO Auto-generated method stub

		// 读取设置阈值
		JSONReadUtil jsonReadUtil = new JSONReadUtil();
		@SuppressWarnings("static-access")
		String jsonstr = jsonReadUtil.readFile(path);
		JSONObject jsonsetp = JSONObject.fromObject(jsonstr);

		Date date = new Date();
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String time = format.format(date);
		// String time =String.valueOf(System.currentTimeMillis()/1000);
		List<JSON> jsons = new ArrayList<JSON>();

		for (int i = 0; i < eventlist.size(); i++) {

			String Severity = sum(jsonsetp.getInt("severitymax"), jsonsetp.getInt("severitymin"));
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("SourceID", "3");
			map.put("SourceEventID", "ER" + i);
			map.put("SourceCIName", eventlist.get(i));
			map.put("SourceAlertKey", "er");
			map.put("Severity", Severity);
			map.put("SourceSeverity", Severity);
			map.put("Status", "1");
			map.put("Summary", "设备编号为" + eventlist.get(i) + "的设备异常！");
			map.put("LastOccurrence", time);
			map.put("SourceIdentifier", "");
			JSONObject jsonObj = JSONObject.fromObject(map);
			jsons.add(jsonObj);
		}

		return jsons;
	}

	/**
	 * tarsier-itvop 自定义参数产生告警数据
	 * 
	 * @param eventlist 告警的设备编号集合
	 * @return
	 */
	public List<JSON> eventManages(List<String> eventlist, String content, String path) {
		Date date = new Date();
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String time = format.format(date);
		// String time =String.valueOf(System.currentTimeMillis()/1000);
		List<JSON> jsons = new ArrayList<JSON>();

		// 读取设置阈值
		JSONReadUtil jsonReadUtil = new JSONReadUtil();
		@SuppressWarnings("static-access")
		String jsonstr = jsonReadUtil.readFile(path);
		JSONObject jsonsetp = JSONObject.fromObject(jsonstr);

		for (int i = 0; i < eventlist.size(); i++) {

			String Severity = sum(jsonsetp.getInt("severitymax"), jsonsetp.getInt("severitymin"));
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("SourceID", "3");
			map.put("SourceEventID", "ER" + i);
			map.put("SourceCIName", eventlist.get(i));
			map.put("SourceAlertKey", "er");
			map.put("Severity", Severity);
			map.put("SourceSeverity", Severity);
			map.put("Status", "1");
			map.put("Summary", content);
			map.put("LastOccurrence", time);
			map.put("SourceIdentifier", "");
			JSONObject jsonObj = JSONObject.fromObject(map);
			jsons.add(jsonObj);
		}
		return jsons;
	}

	@Override
	public Map<String, List<String>> shebeilistMange(String peidiangui, String wenshidu, String kongtiao, String UPS,
			String fadianji) {
		Map<String, List<String>> sbmap = new HashMap<String, List<String>>();
		List<String> wsdlist = null;
		List<String> pdglist = null;
		List<String> ktlist = null;
		List<String> UPSlist = null;
		List<String> fdjlist = null;
		if (wenshidu != null) {
			wsdlist = new ArrayList<String>();
			String[] sourceStrArray = wenshidu.split(",");
			for (int i = 0; i < sourceStrArray.length; i++) {
				if (!"".equals(sourceStrArray[i])) {
					wsdlist.add(sourceStrArray[i]);
					// System.out.print(sourceStrArray[i]);
				}
			}
		}
		if (peidiangui != null) {
			pdglist = new ArrayList<String>();
			String[] sourceStrArray = peidiangui.split(",");
			for (int i = 0; i < sourceStrArray.length; i++) {
				if (!"".equals(sourceStrArray[i])) {
					pdglist.add(sourceStrArray[i]);
					// System.out.print(sourceStrArray[i]);
				}
			}
		}
		if (kongtiao != null) {
			ktlist = new ArrayList<String>();
			String[] sourceStrArray = kongtiao.split(",");
			for (int i = 0; i < sourceStrArray.length; i++) {
				if (!"".equals(sourceStrArray[i])) {
					ktlist.add(sourceStrArray[i]);
					// System.out.print(sourceStrArray[i]);
				}
			}
		}
		if (UPS != null) {
			UPSlist = new ArrayList<String>();
			String[] sourceStrArray = UPS.split(",");
			for (int i = 0; i < sourceStrArray.length; i++) {
				if (!"".equals(sourceStrArray[i])) {
					UPSlist.add(sourceStrArray[i]);
					// System.out.print(sourceStrArray[i]);
				}
			}
		}
		if (fadianji != null) {
			fdjlist = new ArrayList<String>();
			String[] sourceStrArray = fadianji.split(",");
			for (int i = 0; i < sourceStrArray.length; i++) {
				if (!"".equals(sourceStrArray[i])) {
					fdjlist.add(sourceStrArray[i]);
					// System.out.print(sourceStrArray[i]);
				}
			}
		}
		sbmap.put("配电柜", pdglist);
		sbmap.put("温湿度", wsdlist);
		sbmap.put("空调", ktlist);
		sbmap.put("UPS", UPSlist);
		sbmap.put("发电机", fdjlist);

		return sbmap;
	}

	/**
	 * 产生服务器监控数据,用于Tarsier
	 * 
	 * @param fuwuqiperfManage
	 * @return
	 */
	public JSON fuwuqiperfManage(List<String> cilist, List<String> kpilist) {
		JSONArray jsonArray = new JSONArray();
		JSON json = new JSONArray();
		// 修改时间戳
		/*
		 * Date date=new Date(); DateFormat format=new SimpleDateFormat(
		 * "yyyy-MM-dd HH:mm:ss"); String time=format.format(date);
		 */
		String time = String.valueOf(System.currentTimeMillis());
		for (int i = 0; i < cilist.size(); i++) {
			for (int j = 0; j < kpilist.size(); j++) {
				JSONObject jsonObj = perf(cilist.get(i), kpilist.get(j), sum(100, 1), " %", "_", time);
				jsonArray.add(jsonObj);
			}
		}
		json = jsonArray;
		// System.out.println(json);
		return json;
	}

	/**
	 * 读取预设值参数
	 * 
	 * @return DongHuan对象动环模拟推送的范围
	 */
	public DongHuan readPerfSetUpJson(String path) {
		// TODO Auto-generated method stub
		JSONReadUtil jsonReadUtil = new JSONReadUtil();
		DongHuan dongHuan = new DongHuan();
		@SuppressWarnings("static-access")
		String jsonstr = jsonReadUtil.readFile(path);
		JSONObject json = JSONObject.fromObject(jsonstr);
		dongHuan.setWsdWDmax(json.getString("wdmax"));
		dongHuan.setWsdWDmin(json.getString("wdmin"));
		dongHuan.setWsdSDmax(json.getString("sdmax"));
		dongHuan.setWsdSDmin(json.getString("sdmin"));

		dongHuan.setKtHFWDmax(json.getString("hfwdmax"));
		dongHuan.setKtHFWDmin(json.getString("hfwdmin"));
		dongHuan.setKtHFSDmax(json.getString("hfsdmax"));
		dongHuan.setKtHFSDmin(json.getString("hfsdmin"));

		dongHuan.setPdgZDYmax(json.getString("zdymax"));
		dongHuan.setPdgZDYmin(json.getString("zdymin"));
		dongHuan.setPdgZDLmax(json.getString("zdlmax"));
		dongHuan.setPdgZDLmin(json.getString("zdlmin"));

		dongHuan.setUpsSRDYmax(json.getString("srdymax"));
		dongHuan.setUpsSRDYmin(json.getString("srdymin"));
		dongHuan.setUpsSCDYmax(json.getString("scdymax"));
		dongHuan.setUpsSCDYmin(json.getString("scdymin"));

		dongHuan.setFdjDYmax(json.getString("dymax"));
		dongHuan.setFdjDYmin(json.getString("dymin"));
		dongHuan.setFdjDLmax(json.getString("dlmax"));
		dongHuan.setFdjDLmin(json.getString("dlmin"));

		return dongHuan;
	}

	public boolean writePerfSetUpJson(String path, DongHuan dongHuan) {
		JSONReadUtil jsonReadUtil = new JSONReadUtil();
		@SuppressWarnings("static-access")
		String jsonstr = jsonReadUtil.readFile(path);
		JSONObject json = JSONObject.fromObject(jsonstr);
		if ("" != dongHuan.getWsdWDmax()) {
			json.put("wdmax", dongHuan.getWsdWDmax());
		}
		if ("" != dongHuan.getWsdWDmin()) {
			json.put("wdmin", dongHuan.getWsdWDmin());
		}
		if ("" != dongHuan.getWsdSDmax()) {
			json.put("sdmax", dongHuan.getWsdSDmax());
		}
		if ("" != dongHuan.getWsdSDmin()) {
			json.put("sdmin", dongHuan.getWsdSDmin());
		}
		if ("" != dongHuan.getKtHFWDmax()) {
			json.put("hfwdmax", dongHuan.getKtHFWDmax());
		}
		if ("" != dongHuan.getKtHFWDmin()) {
			json.put("hfwdmin", dongHuan.getKtHFWDmin());
		}
		if ("" != dongHuan.getKtHFSDmax()) {
			json.put("hfsdmax", dongHuan.getKtHFSDmax());
		}
		if ("" != dongHuan.getKtHFSDmin()) {
			json.put("hfsdmin", dongHuan.getKtHFSDmin());
		}
		if ("" != dongHuan.getPdgZDYmax()) {
			json.put("zdymax", dongHuan.getPdgZDYmax());
		}
		if ("" != dongHuan.getPdgZDYmin()) {
			json.put("zdymin", dongHuan.getPdgZDYmin());
		}
		if ("" != dongHuan.getPdgZDLmax()) {
			json.put("zdlmax", dongHuan.getPdgZDLmax());
		}
		if ("" != dongHuan.getPdgZDLmin()) {
			json.put("zdlmin", dongHuan.getPdgZDLmin());
		}
		if ("" != dongHuan.getUpsSRDYmax()) {
			json.put("srdymax", dongHuan.getUpsSRDYmax());
		}
		if ("" != dongHuan.getUpsSRDYmin()) {
			json.put("srdymin", dongHuan.getUpsSRDYmin());
		}
		if ("" != dongHuan.getUpsSCDYmax()) {
			json.put("scdymax", dongHuan.getUpsSCDYmax());
		}
		if ("" != dongHuan.getUpsSCDYmin()) {
			json.put("scdymin", dongHuan.getUpsSCDYmin());
		}
		if ("" != dongHuan.getFdjDYmax()) {
			json.put("dymax", dongHuan.getFdjDYmax());
		}
		if ("" != dongHuan.getFdjDYmin()) {
			json.put("dymin", dongHuan.getFdjDYmin());
		}
		if ("" != dongHuan.getFdjDLmax()) {
			json.put("dlmax", dongHuan.getFdjDLmax());
		}
		if ("" != dongHuan.getFdjDLmin()) {
			json.put("dlmin", dongHuan.getFdjDLmin());
		}
		boolean rel = jsonReadUtil.writeFile(json.toString(), path);
		return rel;
	}

	@Override
	public Event readEventSetUpJson(String path) {
		// TODO Auto-generated method stub
		JSONReadUtil jsonReadUtil = new JSONReadUtil();
		Event event = new Event();
		@SuppressWarnings("static-access")
		String jsonstr = jsonReadUtil.readFile(path);
		JSONObject json = JSONObject.fromObject(jsonstr);
		event.setSeveritymax(json.getString("severitymax"));
		event.setSeveritymin(json.getString("severitymin"));
		return event;
	}

	@Override
	public boolean writeEventSetUpJson(String path, Event event) {
		// TODO Auto-generated method stub
		JSONReadUtil jsonReadUtil = new JSONReadUtil();
		@SuppressWarnings("static-access")
		String jsonstr = jsonReadUtil.readFile(path);
		JSONObject json = JSONObject.fromObject(jsonstr);
		if ("" != event.getSeveritymax()) {
			json.put("severitymax", event.getSeveritymax());
		}
		if ("" != event.getSeveritymin()) {
			json.put("severitymin", event.getSeveritymin());
		}
		boolean rel = jsonReadUtil.writeFile(json.toString(), path);
		return rel;
	}
}
